
ssc install metan

cd ""


insheet using "study_comparison_w_pooled.csv", clear
metan late lb95 ub95 if num==4 | num==5 | num==6 | num==7 | num==8, wgt(n)

disp 1.053255/.408
disp 1.053255/.3619855

disp .408/.0089307
disp .4271751/.0089307

insheet using "study_comparison_message_pooled.csv", clear
metan late lb95 ub95 if num==3 | num==4 | num==5 | num==6 | num==7, wgt(n)

insheet using "study_comparison_lt_dating_w_pooled.csv", clear
metan late lb95 ub95 if  num==3 | num==4 | num==5 | num==6 | num==7, wgt(n)

*** For the 18-35 Figure
insheet using "study_comparison_18_35_w_pooled.csv", clear
metan late lb95 ub95 if num==4 | num==5 | num==6 | num==7 | num==8, wgt(n)


*** For the Scales Figure
insheet using "study_comparison_factor_weight_scales.csv", clear
metan late lb95 ub95 if num==2 | num==3 | num==4 | num==5, wgt(n)



















************ FOR THE PERMUTATION TEST [ENDED UP CUTTING THIS]


******** EXPERIMENT 1
cd "" // update this based on what computer you are on.

insheet using "democracy of dating raw data.csv", clear

keep q20 q40_1 q23_1 q46_1 q34_1 q51_1 q28_1

*partyid
sort q20
tab q20
encode(q20), gen(partyid)

gen attractiveness_score=q40_1
replace attractiveness_score=q46_1 if attractiveness_score==.
replace attractiveness_score=q51_1 if attractiveness_score==.
replace attractiveness_score=q23_1 if attractiveness_score==.
replace attractiveness_score=q34_1 if attractiveness_score==.
replace attractiveness_score=q28_1 if attractiveness_score==.

egen attractiveness_score_std=std(attractiveness_score), mean(0) std(1)

**Create Treatment
gen treatment=0 if q40_1~=. | q23_1~=. // control: saw no partisan information (female first, male second)
replace treatment=1 if q46_1~=. | q34_1~=. // republican (female first, male second)
replace treatment=2 if q51_1~=. | q28_1~=. // democrat (female first, male second)

**Create same party variable (same party of profile as viewer)
gen same_party = .
replace same_party = 1 if partyid == 1 & treatment == 2
replace same_party = 1 if partyid == 2 & treatment == 1
replace same_party = 0 if partyid == 1 & treatment == 1
replace same_party = 0 if partyid == 2 & treatment == 2

keep same_party attractiveness_score_std
keep if same_party~=.

save "experiment1.dta", replace

*********** EXPERIMENT 2

cd "" // change this if you're working on another computer

use "CCES18_BYU_OUTPUT.DTA", clear

*recode the variables for easier usage
gen attractiveness_score=.
replace attractiveness_score=BYU307 if BYU307<=100

egen attractiveness_score_std=std(attractiveness_score), mean(0) std(1)

gen same_party=.
replace same_party=1 if BYU306==1 & BYU307rand==3
replace same_party=1 if BYU306==2 & BYU307rand==1
replace same_party=0 if BYU306==1 & BYU307rand==1
replace same_party=0 if BYU306==2 & BYU307rand==3

keep same_party attractiveness_score_std
keep if same_party~=.

save "experiment2.dta", replace

************ EXPERIMENT 3

cd ""

insheet using "Holbein Winter 2019_March 7, 2019_15.13.csv", clear

gen demand_effects=1 if  fl_11_do_datingintrodemandeffect==1
replace demand_effects=0 if  fl_11_do_datingintro==1

*fixing partyid
gen viewer_party = .
replace viewer_party = 0 if q13 == "Democrat"
replace viewer_party = 1 if q13 == "Independent"
replace viewer_party = 2 if q13 == "Republican"

gen treatment=0 if q20_1~=. | q38_1~=. // control: saw no partisan information (female first, male second)
replace treatment=1 if q32_1~=. | q50_1~=. // republican (female first, male second)
replace treatment=2 if q26_1~=. | q44_1~=. // democrat (female first, male second)

gen same_party = .
replace same_party = 1 if viewer_party == 0 & treatment == 2
replace same_party = 1 if viewer_party == 2 & treatment == 1

replace same_party = 0 if viewer_party == 0 & treatment == 1
replace same_party = 0 if viewer_party == 2 & treatment == 2

gen attractiveness_score=q20_1
replace attractiveness_score=q38_1 if attractiveness_score==.
replace attractiveness_score=q32_1 if attractiveness_score==.
replace attractiveness_score=q50_1 if attractiveness_score==.
replace attractiveness_score=q26_1 if attractiveness_score==.
replace attractiveness_score=q44_1 if attractiveness_score==.

egen attractiveness_score_std=std(attractiveness_score), mean(0) std(1)

keep if demand_effects==0

keep same_party attractiveness_score_std
keep if same_party~=.

save "experiment3.dta", replace

******** EXPERIMENT 4

cd ""

import delimited "Dating Survey 4_April 22, 2019_16.00.csv", encoding(ISO-8859-1) clear

gen treatment=0 if fl_33_do_control==1 | fl_34_do_control==1 | fl_35_do_control==1 // control: saw no partisan information (female first, male second)
replace treatment=1 if fl_33_do_republican==1 | fl_34_do_republican==1 | fl_35_do_republican==1 // republican (female first, male second)
replace treatment=2 if fl_33_do_democrat==1 | fl_34_do_democrat==1 | fl_35_do_democrat==1 // democrat (female first, male second)

gen attractiveness_score=q40_1
replace attractiveness_score=q28 if attractiveness_score==.
egen attractiveness_score_std=std(attractiveness_score), mean(0) std(1)

gen same_party = .
replace same_party = 0 if q13 == 1 & treatment == 2
replace same_party = 0 if q13 == 2 & treatment == 1
replace same_party = 1 if q13 == 1 & treatment == 1
replace same_party = 1 if q13 == 2 & treatment == 2

keep same_party attractiveness_score_std
keep if same_party~=.

save "experiment4.dta", replace

******** EXPERIMENT 5

cd ""

import delimited "final dataset.csv", clear 

gen female_control=1 if q20_1~=.
gen female_democrat=1 if q151_1~=.
gen female_liberal=1 if q185_1~=.
gen female_sanders=1 if q191_1~=.
gen female_republican=1 if q161_1~=.
gen female_conservative=1 if q204_1~=.
gen female_trump=1 if q210_1~=.

gen male_control=1 if q38_1~=.
gen male_democrat=1 if q253_1~=.
gen male_liberal=1 if q265_1~=.
gen male_sanders=1 if q277_1~=.
gen male_republican=1 if q173_1~=.
gen male_conservative=1 if q237_1~=.
gen male_trump=1 if q243_1~=.

gen control=1 if female_control==1 | male_control==1
gen democrat=1 if female_democrat==1 | male_democrat==1
gen liberal=1 if female_liberal==1 | male_liberal==1
gen sanders=1 if female_sanders==1 | male_sanders==1
gen republican=1 if female_republican==1 | male_republican==1
gen conservative=1 if female_conservative==1 | male_conservative==1
gen trump=1 if female_trump==1 | male_trump==1

gen none=1 if control==. &  democrat==. &  liberal==. &  sanders==. &  republican==. &  conservative==. &  trump==. 

foreach var in control democrat liberal sanders republican conservative trump {
replace `var'=0 if `var'==. & none~=1
}

drop if none==1

gen attractiveness_score=q20_1
replace attractiveness_score=q151_1 if attractiveness_score==.
replace attractiveness_score=q185_1 if attractiveness_score==.
replace attractiveness_score=q191_1 if attractiveness_score==.
replace attractiveness_score=q161_1 if attractiveness_score==.
replace attractiveness_score=q204_1 if attractiveness_score==.
replace attractiveness_score=q210_1 if attractiveness_score==.
replace attractiveness_score=q38_1 if attractiveness_score==.
replace attractiveness_score=q253_1 if attractiveness_score==.
replace attractiveness_score=q265_1 if attractiveness_score==.
replace attractiveness_score=q277_1 if attractiveness_score==.
replace attractiveness_score=q173_1 if attractiveness_score==.
replace attractiveness_score=q237_1 if attractiveness_score==.
replace attractiveness_score=q243_1 if attractiveness_score==.

egen attractiveness_score_std=std(attractiveness_score), mean(0) std(1)


gen same_candidate=1 if q159=="Bernie Sanders" & sanders==1
replace same_candidate=1 if q159=="Donald Trump" & trump==1
replace same_candidate=0 if same_candidate==.

gen same_party=1 if q13=="Democrat" & democrat==1
replace same_party=1 if q13=="Republican" & republican==1
replace same_party=0 if same_party==. & q13~="Independent"

gen same_ideology=1 if (q12=="Liberal" | q12=="Very liberal") & liberal==1
replace same_ideology=1 if (q12=="Conservative" | q12=="Very conservative") & conservative==1
replace same_ideology=0 if same_ideology==. & q12~="Moderate"

keep same_party attractiveness_score_std

save "experiment5.dta", replace


*********** Bringing Them All Together
cd "" // update this based on what computer you are on.

use "experiment1.dta", clear
append using "experiment2.dta"
append using "experiment3.dta"
append using "experiment4.dta"
append using "experiment5.dta"

reg attractiveness_score_std same_party

permute attractiveness_score_std "reg attractiveness_score_std same_party" _b, reps(1000) saving("treatment_permute")

use "treatment_permute.dta", clear
saveold "treatment_permute.dta", version(12) replace
